using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;

namespace FiltronASP.Helpers.HashExtensions
{
    /// <summary>
    /// Metoda zawierajaca rozszerzenia do algorytmow hashujacych c#.
    /// </summary>
    public static class HashExtensions
    {
        /// <summary>
        /// Metoda obliczajaca hash na podstawie zadanych parametrow.
        /// </summary>
        /// <param name="hashAlgorithm">algorytm hashujacy</param>
        /// <param name="data">dane do zahashowania</param>
        /// <param name="encoding">kodowania</param>
        /// <returns>hash</returns>
        public static byte[] ComputeHash(this HashAlgorithm hashAlgorithm, string data, Encoding encoding)
        {
            byte[] bytes = encoding.GetBytes(data);
            return hashAlgorithm.ComputeHash(bytes);
        }

        /// <summary>
        /// Metoda obliczajaca hash na podstawie zadanych parametrow, domyslne kodowanie utf-8.
        /// </summary>
        /// <param name="hashAlgorithm">algorytm hashujacy</param>
        /// <param name="data">dane do zahashowania</param>
        /// <returns>hash</returns>
        public static byte[] ComputeHash(this HashAlgorithm hashAlgorithm, string data)
        {
            return hashAlgorithm.ComputeHash(data, Encoding.UTF8);
        }
    }

}
